window.onload = function() {
    let toTop = document.querySelector('.return')
    let totop = document.querySelector('.totop')
    console.log(toTop);
    let timerID = null

    function back() {
        timerID = setInterval(function() {
            document.documentElement.scrollTop -= 50
            if (document.documentElement.scrollTop <= 0) {
                clearInterval(timerID)
                timerID = null
            }
        }, 30)
    }
    back()

    toTop.addEventListener('click', function() {
        back()
    })
    totop.addEventListener('click', function() {
        console.log(11);
        back()

    })
    window.addEventListener('scroll', function() {
        if (document.documentElement.scrollTop >= 500) {
            totop.style.display = 'block'
        } else {
            totop.style.display = 'none'
        }
    })
    let colors = document.querySelectorAll('.color')
    colors.forEach(function(color, index) {
        color.addEventListener('click', function() {
            colors.forEach(function(color) {
                color.classList.remove('gray')
            })
            this.classList.add('gray')
        })
    })

}